/*
 * HibernateUtil.java
 * 
 *  author: hibernate.org
 *  
 * Classes:
 *  HiberateUtil
 * 
 */

package ocumed.persistenz.hibernate;


import java.io.File;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/**
 * hibernate helper class from hibernate.org
 */
public class HibernateUtil {

    private static final SessionFactory sessionFactory;
    private static final Log log = LogFactory.getLog(HibernateUtil.class);

    static {
        try {
        	File cfgFile = new File(System.getProperty("hibernate.configfile"));
            Configuration cfg = new Configuration().configure(cfgFile); 
            sessionFactory = cfg.buildSessionFactory();            
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            log.fatal("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex.getMessage());
        }
        
        log.debug("hibernate config loaded");
    }

    /**
     * return the session factory
     * 
     * @return
     */
    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

}